#include "sysv_msg.h"

int main(int argc,char *argv[])
{
  int mqid;
  long type;
  size_t len;
  struct msgbuf *buf;
  
  if(argc != 4)
    err_quit("Usage: msgsnd <pathname> bytes type");
 
  len = atoi(argv[2]); 
  type = atoi(argv[3]); 

  mqid = msgget(ftok(argv[1],0),MSG_W);
  if(mqid ==-1)
    err_sys("msgget error");
  
  buf = (struct msgbuf*)calloc(sizeof(long)+len,sizeof(char)); 
  if(!buf) 
     err_sys("no space");
  
  buf->mtype = type;
  if(msgsnd(mqid,buf,len,0) ==-1)
    err_sys("msgsnd error");
  exit(0);
}
